app.controller('brandController', function ($scope, $controller, brandService) {
    $controller('baseController', {$scope : $scope });//继承

    $scope.findList=function () {
        brandService.findList().success(
            function (response) {
                $scope.list=response;
            });
    }

    //查询列表
    $scope.findPage=function (page,size) {
        brandService.findPage(page, size).success(
            function (response) {
                $scope.list = response.rows;
                $scope.paginationConf.totalItems = response.total;
            }
        );
    }

    //新增
    $scope.save=function () {
        var serviceObject;//服务层对象
        if ($scope.entity.id!=null) {
            serviceObject = brandService.update($scope.entity);
        }else {
            serviceObject = brandService.add($scope.entity);
        }
        serviceObject.success(
            function (response) {
                if (response.success) {
                    $scope.reloadList();//重新加载
                }else {
                    alert(response.message);
                }
            }
        );
    }

    //通过id查询
    $scope.findOne=function (id) {
        brandService.findOne(id).success(
            function (response) {
                $scope.entity=response;
            }
        );
    }

    //删除id
    $scope.dele=function () {
        brandService.dele($scope.selectIds).success(
            function (response) {
                if (response.success) {
                    $scope.reloadList();//重新加载
                }else {
                    alert(response.message);
                }
            }
        );
    }

    //条件查询
    $scope.searchEntity = {};
    $scope.search = function(page, size){
        brandService.search(page, size, $scope.searchEntity).success(
            function (response) {
                $scope.list = response.rows;
                $scope.paginationConf.totalItems = response.total;
            }
        );
    }
});